package cn.net.autocode.platform.config;

import cn.net.autocode.dbManager.Dao;
import cn.net.autocode.platform.factory.SpringBeanFactory;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import java.util.ArrayList;
import java.util.List;


public class PlatFormExcludePath {

    protected static void init(InterceptorRegistration ir){
        List<String> path1 = PlatFormExcludePath.staticPath();
        List<String> path2 = PlatFormExcludePath.dynamicPath();
        path1.addAll(path2);
        ir.excludePathPatterns(path1);
    }


    private static List<String> staticPath(){
        List<String> irs = new ArrayList<>();
        irs.add("/");
        irs.add("/favicon.ico");
        irs.add("/doc.html");
        irs.add("/css/**");
        irs.add("/js/**");
        irs.add("/img/**");
        irs.add("/links/**");
        irs.add("/templates/favicon.ico");
        irs.add("/error");
        irs.add("/platform/main");
        irs.add("/platform/forLogin");
        irs.add("/platform/login");
        irs.add("/mobilePlatform/login");
        irs.add("/platform/relogin");
        irs.add("/platform/phoneRegister");
        irs.add("/platform/emailRegister");
        irs.add("/platform/registerSuccess");
        irs.add("/platform/operSuccess");
        irs.add("/platform/retrievePassword");
        irs.add("/platform/phoneRetrievePassword");
        irs.add("/platform/randomImage/*");
        irs.add("/platform/showXieYi");
        irs.add("/autocode/fileProvider/image");
        irs.add("/autocode/fileProvider/image/*");
        irs.add("/platform/entrance/*");
        irs.add("/platform/page/*/*");
        irs.add("/base/dev/cmpDesign/*/*");//弹出组件设计器页面
        irs.add("/base/pagePreview/*");
        irs.add("/autocode/fileProvider/filePreview/*");
        irs.add("/autocode/fileProvider/previewContent/*");
        irs.add("/notLogin/**");

        //钉钉的请求
        irs.add("/platform/dingTalk/getCorpId");
        irs.add("/platform/dingTalk/login");
        return irs;
    }

    private static List<String> dynamicPath(){
        Dao dao = SpringBeanFactory.getBeanByType(Dao.class);
        return dao.queryListValue("select uri from autocode_exclude_path",String.class);
    }

}
